<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>用户信息</title>
<%@include file="../core/head.jsp"%>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="${ctx }/css/core.css"></link>
<link rel="stylesheet" href="${ctx}/css/regist.css" type="text/css"></link>
<link rel="stylesheet" href="${ctx}/css/buttons.css" type="text/css"></link>
<link rel="stylesheet" href="${ctx}/css/table.css" type="text/css">
<script type="text/javascript"
	src="${ctx}/js/modules/code/MessageBox.js"></script>
<script type="text/javascript"
	src="${ctx}/js/modules/code/AjaxAuthFilter.js"></script>
<script type="text/javascript">
	$(function() {
		if ("${updated}" == "true") {
			$.MessageBox.info("操作成功");
		}
	});
	function generInvite() {
		var email = $("#email").val();
		var mreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		if (mreg.test(email)) {
			$.ajax({
				cache : true,
				type : "POST",
				url : "${ctx}/user/generInvite.action",
				data : {
					"user.email" : email
				},
				error : function(request) {
					if (score.online) {
						$.MessageBox.info("操作失败");
						score.online = false;
					}
	
				},
				success : function(data) {
					var pass = $.AjaxAuthFilter.checkSession(
						"${ctx}/user/ajaxLogin.action", data, function(user) {
							updateUser(user);
							generInvite(data);
						});
					if(pass){
						insertInviteCode(data);
					}
				}
			});
		} else {
			$.MessageBox.info("邮箱格式不正确");
		}
	}
	
	function insertInviteCode(data){
		$.MessageBox.info("操作成功");
		var table = $("#table");
		var id = table.find("tr").size();
		table.append("<tr><td>" + id + "</td><td>"+ data.email + "</td><td>" + data.code+ "</td></tr>");
	
	}
</script>
</head>
<body>
	<%@include file="../exam/top.jsp"%>
	<div class="width center">

		<div class="reg-form  radius">
			<div style="margin: 10px 10px 10px 0px">
				<input type="text" id="email"
					style="width:50%;height:34px;margin-right: 10px;" /><input
					class="button green menuBut" type="button" value="生成"
					onclick="generInvite()" />
			</div>
			<table id="table" class="dtable radius" border="0" cellpadding="0"
				cellspacing="1" style="width: 100%;">
				<tr>
					<th>ID</th>
					<th>email</th>
					<th>code</th>
				</tr>
				<c:forEach var="code" varStatus="temp" items="${codes}">
					<tr>
						<td>${temp.index+1 }</td>
						<td>${code.email }</td>
						<td>${code.code }</td>
					</tr>

				</c:forEach>
			</table>
		</div>

	</div>
	<%@include file="../core/bottom.jsp"%>
</body>
</html>
